# -*- coding: UTF8 -*- 

import win32com.client
 
def send_mail_via_com(text,
                      subject,
                      recipient,
                      profilename="Outlook2003",
                      attachments=[]):
    s = win32com.client.Dispatch("Mapi.Session")
    o = win32com.client.Dispatch("Outlook.Application")
    s.Logon(profilename)
    
    Msg = o.CreateItem(0)
    #Msg.From = "Marian Marinov(Deloitte)<vpresovsky@deloitteCE.com>"
    #Msg.From = "presovsky@gmail.com>"
    Msg.To = recipient
    
    Msg.CC = "vpresovsky@deloitteCE.com"
    Msg.BCC = "vpresovsky@deloitteCE.com"
    #Msg.Charset = "UTF-8"
    
    Msg.Subject = subject
    Msg.Body = text

    if len(attachments) > 0:
        for att in attachments:
            Msg.Attachments.Add(att)
 
    Msg.Send()

attachments=[   "C:\\AFT\\pepe\\template.py",
                "C:\\AFT\\pepe\\__init__.py"]

def parseString(msg):
    msg=unicode(msg)
    Options=dict(   char_encoding='utf8',
                    show_body_only=True,
                    output_html=True,
                    input_encoding='utf8',
                    output_encoding='utf8')
    msg=tidy.parseString(msg.encode('utf8'),**Options)
    #msg=tidy.parseString('test')
    #return msg
    return str(msg).decode('utf8')


mbody = open(u'mail-body.txt','r').read()
msubject = open(u'mail-subject.txt','r').read()
print msubject
print parseString(msubject)

ofile = open(u'mail-body_.txt','w')
ofile.write(mbody)
ofile.close()

"""
send_mail_via_com(  text=mbody,
                    subject=msubject,
                    recipient="vpresovsky@deloitteCE.com",
                    profilename="Deloitte Profile",
                    )

"""



